pygame integration into tkinter

by: Toon Mertens, 8 years ago


I'm programming a GPS app for my raspberry pi. I made a few GUI's, with tkinter, where I can switch between them by clicking some buttons. To show my GPS data I want to use pygame. I made these two seperated and now I would like to integrate the pygame code into my tkinter code. By pushing the button GPS I want to go to my pygame code.

I've tried a few things already.

class Settings(tk.Frame):

    def __init__(self, parent, controller):
            tk.Frame.__init__(self, parent)
            label = tk.Label(self, text='Maaien', font=LARGE_FONT)
            label.pack( padx=50, pady=10)


            settingsTractor = PhotoImage(file='TractorGPSbig.png')
            label = tk.Label(self,image=settingsTractor)
            label.pack()


            buttonHome = tk.Button(self, text='Home', command=lambda: controller.show_frame(StartPage))
            buttonHome.pack()


            buttonGPS = tk.Button(self, text='GPS',command=lambda: controller.show_frame(gpsFrame))
            buttonGPS.pack()


class gpsFrame(tk.Frame):`

    def __init__(self, parent, controller):

            tk.Frame.__init__(self, parent)
            embed = tk.Frame(self,width=800, height=600)    #create embedded frame for pyGame
            embed.grid(columnspan=700, rowspan=400)         #add s grid
            embed.pack(side='left')

            buttonwin = tk.Frame(self, width=75, height=500)
            buttonwin.pack(side='left')
            os.environ['SDL_WINDOWID']= str(embed.winfo_id())
            os.environ['SDL_VIDEODRIVER'] = 'winid'

            screen = pygame.display.set_mode((200,200))
            screen.fill(pygame.color(206,206,206))
            pygame.display.init()
            pygame.display.update()
But when I use this code I get an error:

X Error of failed request:  BadWindow (invalid Window parameter)  
Major opcode of failed request:  3 (X_GetWindowAttributes)   Resource
id in failed request:  0x1c00018   Serial number of failed request:
52   Current serial number in output stream:  53
I also tried changing

buttonGPS = tk.Button(self, text='GPS',command=lambda: controller.show_frame(gpsFrame))
                buttonGPS.pack()
to

buttonGPS = tk.Button(self, text='GPS',command=app.destroy)
                buttonGPS.pack()
This I get why it doesn't work. Any Idea how to solve this?



You must be logged in to post. Please login or register an account.



I have absolutely no idea here. This is a good stackoverflow question. It might take a bit for someone knowledgeable to answer this question, but that's my best suggestion.

-Harrison 8 years ago

You must be logged in to post. Please login or register an account.